package com.autumn.zero.workflow.values;

import java.util.HashMap;
import java.util.Map;

import javax.validation.constraints.NotNull;

import com.autumn.common.api.application.DataValidation;
import com.autumn.domain.vo.AbstractValue;
import com.autumn.validation.ValidationUtils;
import com.autumn.validation.annotation.NotNullOrBlank;
import com.autumn.zero.workflow.constants.ProcessExecutConstants;

/**
 * 流程启动值
 * 
 * @author 杨昌国 2019-01-24 15:15:34
 */
public class ProcessStartValue extends AbstractValue implements DataValidation {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2922093488519641656L;

	/**
	 * 表单类型
	 */
	@NotNull(message = "表单类型不能为空")
	private Integer formType;

	/**
	 * 表单id
	 */
	@NotNull(message = "表单id不能为空")
	private Long formId;

	/**
	 * 表单号
	 */
	@NotNullOrBlank(message = "表单号不能为空")
	private String formNo;

	/**
	 * 表单标题
	 */
	@NotNullOrBlank(message = "标题不能为空")
	private String flowTitle;

	/**
	 * 启动用户
	 */
	@NotNull(message = "启动用户id不能为空")
	private String startUserId;

	/**
	 * 表单标题
	 */
	@NotNullOrBlank(message = "启动用户名称不能为空")
	private String startUserName;

	/**
	 * 表单变量
	 */
	private Map<String, Object> formVariables;

	/**
	 * 实例化
	 */
	public ProcessStartValue() {
		this.setFormVariables(new HashMap<>());
	}

	public Integer getFormType() {
		return formType;
	}

	public void setFormType(Integer formType) {
		this.formType = formType;
	}

	public Long getFormId() {
		return formId;
	}

	public void setFormId(Long formId) {
		this.formId = formId;
	}

	public String getFormNo() {
		return formNo;
	}

	public void setFormNo(String formNo) {
		this.formNo = formNo;
	}

	public String getFlowTitle() {
		return flowTitle;
	}

	public void setFlowTitle(String flowTitle) {
		this.flowTitle = flowTitle;
	}

	public String getStartUserId() {
		return startUserId;
	}

	public void setStartUserId(String startUserId) {
		this.startUserId = startUserId;
	}

	public String getStartUserName() {
		return startUserName;
	}

	public void setStartUserName(String startUserName) {
		this.startUserName = startUserName;
	}

	public Map<String, Object> getFormVariables() {
		return formVariables;
	}

	public void setFormVariables(Map<String, Object> formVariables) {
		this.formVariables = formVariables;
	}

	@Override
	public void valid() {
		ValidationUtils.validation(this);
	}

	/**
	 * 放入变量
	 * 
	 * @param variables 变量
	 */
	public Map<String, Object> createVariable() {
		Map<String, Object> variables = new HashMap<>();
		if (this.getFormVariables() != null) {
			variables.putAll(this.getFormVariables());
		}
		variables.put(ProcessExecutConstants.VARIABLE_FORM_TYPE, this.getFormType());
		variables.put(ProcessExecutConstants.VARIABLE_FORM_ID, this.getFormId());
		variables.put(ProcessExecutConstants.VARIABLE_FORM_NO, this.getFormNo());
		variables.put(ProcessExecutConstants.VARIABLE_FLOW_TITLE, this.getFlowTitle());
		variables.put(ProcessExecutConstants.VARIABLE_START_USER_ID, this.getStartUserId());
		variables.put(ProcessExecutConstants.VARIABLE_START_USER_NAME, this.getStartUserName());
		return variables;
	}
}
